<template>
	<view class="">
		<!-- 登陆密码 -->
		 <view class="bg-f has-pd-20" @tap="editpass">
		 	<text>登陆密码</text>
			<view class="has-floatr is-grey has-right-icon">
				修改
				<image src="../../static/img/common/right_ico_grey.png" mode="" ></image>
			</view>			
		 </view>
		 <!-- 身份认证 -->
		  <view class="bg-f has-pd-20" @tap="editcard">
		  	<text>身份认证</text>
		 	<view class="has-floatr is-grey has-right-icon">
		 		{{ user_card_rz ===0 ? '未认证' : '已认证'}}
		 		<image src="../../static/img/common/right_ico_grey.png" mode="" ></image>
		 	</view>			
		  </view>
		 <!-- 语音 -->
		 <view class="bg-f has-pd-20 has-mgt-20">
		  <view class="swiper-list">
				 <view class="uni-list-cell uni-list-cell-pd">
					 <view class="uni-list-cell-db has-floatl">语音</view>
					 <switch :checked="indicatorDots" @change="changeIndicatorDots" class="has-floatr"/>
				 </view>			 
				</view>
		 </view>
		 <view class="bg-f has-pd-20 has-mgt-20" v-show="version">
		  <text>版本{{version}}</text>
		  <view class="has-floatr is-grey has-right-icon" @tap="updateit">
		  	检查升级
		  </view>
		 </view>
		 <!-- 退出登陆 -->
		 <view class="has-pd-20">
			 <button type="warn" @click="outme" class="z-yello">退出登陆</button>
		 </view>
		 <view>
		     <show-modal></show-modal>
		 </view>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				indicatorDots:false,
				userinfo:[],
				foxtoken:'',
				user_card_rz:0,
				version:''
			}
		},
		onShow:function(e){
			let page = getCurrentPages().pop(); //跳转页面成功之后
			if (!page) return;
			this.getuser();
		},
		onLoad() {
			// #ifdef APP-PLUS
			//升级检测数据
			var appid = plus.runtime.appid;
			var version = plus.runtime.version;
			var imei = plus.device.imei;
			var typeapp = plus.os.name;
			// this.version = version;
			plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
				this.version = wgtinfo.version;//应用版本号
			})
			// #endif
		    this.indicatorDots = uni.getStorageSync('music');
			this.getuser();
		},
		methods:{
			changeIndicatorDots:function(e){
				let music = e.detail.value;
				uni.setStorageSync('music', music);
			},
			outme:function(){
				uni.clearStorageSync();
				uni.navigateTo({
					url:'/pages/index/index'
				})
			},
			editpass:function(){
				uni.navigateTo({
					url:'./changepassword'
				})
			},
			editcard:function(){
				uni.navigateTo({
					url:'./changecard'
				})
			},
			getuser(){
				let info = this.service.getfox();
				if(info[0]){
					this.foxtoken = info[0]['foxtoken'];
					uni.request({
						url: this.service.FOX_URL + 'diamond/get_userinfo',
						method:'POST',
						data: {
							user_key: this.foxtoken
						},
						dataType:'json',
						header:{
							'content-type':'application/x-www-form-urlencoded',
						},
						success: res => {
							// var rest = JSON.stringify(res);
							// console.log(res)
							var rest = res.data;
							if(rest.status == 'success'){
								this.userinfo = rest.msg;
								this.user_card_rz = this.userinfo['user_card_rz']
								// console.log(this.userinfo)
							}else{
								uni.showToast({
									title:rest.msg,
									icon:'none',
									mask:true
								})
							}
						}
					})
				}else{
					uni.reLaunch({
						url:'../logon/login'
					})
				}
			},
			updateit(){
				// #ifdef APP-PLUS
				//升级检测数据
				var appid = plus.runtime.appid;
				var version = plus.runtime.version;
				var imei = plus.device.imei;
				var typeapp = plus.os.name;
				plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
					version = wgtinfo.version;//应用版本号
				})

				var checkUpdate = this.service.FOX_URL+"diamond/checkupdate/" + typeapp; //检查更新地址 
				// console.log(checkUpdate);
				uni.request({
					url: checkUpdate,
					dataType:'json',              
					success: (res) => {
						var foxmsg = res.data;
						// console.log(foxmsg)
						if (foxmsg.code == 200) {
							if(foxmsg.data.uptype == 1 && version < foxmsg.data.version){
							// if(foxmsg.data.uptype == 1){
								let uplock = foxmsg.data.uplock;
								let uptext = this.service.FOX_NAME + '平台版本已更新，请跟上升级';
								if(foxmsg.data.uptext){
									uptext = foxmsg.data.uptext;
								}
								if(uplock == 1){
									this.$showModal({ //提醒用户更新
										title: "版本更新",
										content: uptext,
										confirmText:'在线更新',
										showCancel:false,
										success: (res) => {
											if (res.confirm) {
												plus.runtime.openURL(foxmsg.data.downurl);
											}
										}
									})
								}else{
									this.$showModal({ //提醒用户更新
										title: "版本更新",
										content: uptext,
										confirmText:'我要更新',
										cancelText:'暂时不',
										success: (res) => {
											if (res.confirm) {
												plus.runtime.openURL(foxmsg.data.downurl);
											}
										}
									})
								}                            
							}else{
								uni.showToast({
									title:'系统当前最新版本'+this.version,
									icon:'none',
									mask:true
								})
							}                   
						}
					}
				})
				// #endif
			}
		}
		
	}
</script>

<style>
	.has-right-icon image{
		width:40rpx;
		height: 40rpx;
		vertical-align: middle;
		margin-left: 20rpx;
	}
	.swiper-list{
		height: 60rpx;
	}
	.z-yello{
		background: #efb336;
	}
</style>
